<template>
    <div class="financialHistoryPop">
        <backHeader title="收益详情" :fn="backFn" />
        <div class="financialHistoryPop-box">
            <header class="box-header">
                <div class="header-top flex items-center">
                    <div class="flex-1 text-center">
                        <p class="py-10 font-28">3.943972</p>
                        <p class="py-10 font-26 font-700 textColor4">昨日收益</p>
                    </div>
                    <div class="flex-1 text-center">
                        <p class="py-10 font-28">+0</p>
                        <p class="py-10 font-26 font-700 textColor4">7天收益(USDT)</p>
                    </div>
                    <div class="flex-1 text-center">
                        <p class="py-10 font-28">+43.066155</p>
                        <p class="py-10 font-26 font-700 textColor4">30天收益(USDT)</p>
                    </div>
                </div>
                <div class="text-center py-20">
                    <p class="font-30 mb-8" style="color: #9e9e9e;">总收益</p>
                    <p class="font-38 mb-8 font-700" style="color: #01bd8d;">+3.500314</p>
                    <p class="font-32" style="color: #888888;"><span class="center-time">2024-12-21</span></p>
                </div>
                <div class="header-bottom">
                    <div class="bottom-chart" ref="chart"></div>
                    <div class="flex items-center justify-between px-20 font-26" style="color: #656568;">
                        <p>2024-12-01</p>
                        <p>2024-12-21</p>
                    </div>
                </div>
            </header>
            <main class="box-main">
                <van-list class="main-list" v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad" :immediate-check="false">
                    <van-collapse v-model="activeNames" accordion> 
                        <van-collapse-item :name="item.id" v-for="item in listData" :key="item.id">
                            <template #title>
                                <div class="title-left">
                                    <p class="mb-10 font-28">收益</p>
                                    <p class="font-26" style="color: #7e7e7e;">{{ item.time }}</p>
                                </div>
                            </template>
                            <template #right-icon>
                                <div class="title-right">
                                    <p class="mb-10 font-28" style="color: #00911a;">{{ item.num }} {{ item.currency }}</p>
                                    <p class="flex items-center font-28" style="color: #4366e3;">
                                        <span class="mr-5">看明细</span>
                                        <span :class="['arrow-right',item.id === activeNames ? 'active':'']"></span>
                                    </p>
                                </div>
                            </template>
                            <template #default>
                                <table class="default-content">
                                    <tr>
                                        <th>交易日期</th>
                                        <th>收益</th>
                                    </tr>
                                    <tr v-for="item2 in item.data" :key="item2.id">
                                        <th style="font-weight: 500;">{{ item2.time }}</th>
                                        <th style="font-weight: 500;">{{ item2.value }}</th>
                                    </tr>
                                </table>
                            </template>
                        </van-collapse-item>
                    </van-collapse>
                </van-list>
            </main>
        </div>
    </div>
</template>

<script>
import backHeader from '@/components/backHeader/index.vue';
import * as echarts from 'echarts';
import { Collapse, CollapseItem, List } from 'vant';

export default {
    components:{
        backHeader,
        [Collapse.name]:Collapse,
        [CollapseItem.name]:CollapseItem,
        [List.name]:List,
    },
    data() {
        return {
            myChart:null,
            activeNames:'',
            loading:false,
            finished:false,
            listData:[
                {
                    id:0,
                    num:123,
                    currency:'USDT',
                    time:'2024-12-20',
                    data:[
                        {
                            id:0,
                            time:'00:00:01',
                            value:'0.116196'
                        },
                        {
                            id:1,
                            time:'01:00:00',
                            value:'0.177196'
                        },
                        {
                            id:2,
                            time:'02:00:00',
                            value:'0.118886'
                        },
                    ]
                },
                {
                    id:1,
                    num:333,
                    currency:'USDT',
                    time:'2024-11-11',
                    data:[
                        {
                            id:0,
                            time:'00:00:01',
                            value:'300'
                        },
                        {
                            id:1,
                            time:'01:00:00',
                            value:'200'
                        },
                        {
                            id:2,
                            time:'02:00:00',
                            value:'100'
                        },
                    ]
                },
                {
                    id:2,
                    num:888,
                    currency:'USDT',
                    time:'2024-11-10',
                    data:[
                        {
                            id:0,
                            time:'00:00:01',
                            value:'4567'
                        },
                        {
                            id:1,
                            time:'01:00:00',
                            value:'8954'
                        },
                        {
                            id:2,
                            time:'02:00:00',
                            value:'6622'
                        },
                    ]
                },
            ],
        }
    },
    mounted() {
        this.$nextTick(()=>{
            this.myChart = echarts.init(this.$refs['chart']);
            this.init();
        })
    },
    methods: {
        backFn(){
            this.$emit('close',false);
        },
        onLoad(){

        },
        init(){
            const option = {
                xAxis: {
                    show:false,
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                },
                yAxis: {
                    type: 'value',
                    axisTick:{ // y轴刻度线
                        show:false
                    },
                    axisLine:{ // y轴
                        show:false
                    },
                    axisLabel: {
                        show: false // y轴坐标值
                    },
                    splitLine :{
                        lineStyle:{
                            color:'#f5f5f5'
                        },
                    },
                    splitNumber: 4
                },
                series: [
                    {
                        data: [3.1, 3.2, 3.5, 1, 4,2, 3.6],
                        type: 'line',
                        symbol: "none",
                        lineStyle: { // 设置线条的style等
                            normal: {
                                width:5, 
                                color: '#01BD8D',
                            },
                        },
                    }
                ],
                grid: {
                    top: '3%',
                    left: '3%',
                    right: '3%',
                    bottom: '3%',
                    containLabel: true
                },
            };
            this.myChart.setOption(option);
        }
    },
}
</script>

<style lang="scss" scoped>
.financialHistoryPop{
    width: 100%;
    height: 100%;
    background-color: #f4f6f8;
    padding: 0 20px 20px;
    box-sizing: border-box;
    .box-header{
        background-color: #fff;
        margin: 40px 0;
        border-radius: 12px;
        padding: 20px 0;
        .header-top{
            border-bottom: 2px solid #f5f5f5;
        }
        .center-time{
            background-color: #f5f5f5;
            padding: 4px;
            border-radius: 12px;
        }
        .header-bottom{
            .bottom-chart{
                width: 100%;
                height: 220px;
            }
        }
    }
    ::v-deep .box-main{
        .main-list{
            .title-left{
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: flex-start;
            }
            .title-right{
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: flex-end;
            }
            .default-content{
                text-align: center;
                width: 100%;
                color: #000;
                font-size: 26px;
                th{
                    width: 50%;
                }
            }
            .van-collapse-item{
                margin-bottom: 30px;
                border-radius: 12px;
                overflow: hidden;
                &:nth-last-of-type(1){
                    margin-bottom: 0;
                }
            }
            .van-cell{
                padding: 14px;
                color: #000;
            }
        }
        .arrow-right {
            width: 11px;
            height: 11px;
            border-right: 1px solid blue;
            border-top: 1px solid blue;
            transform: rotate(45deg);
            transition: transform .3s;
        }
        .active{
            transform: rotate(135deg);
        }
    }
}
</style>